<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Serenity
 * Date: 29-6-11
 * Time: 14:12
 * To change this template use File | Settings | File Templates.
 */

require_once(Config::acquire("Model", null, "model"));
require_once(Config::acquire('Question', MODEL));
require_once(Config::acquire('QuestionQueue', MODEL));
class QuestionQueue extends Model
{

     /**
     * initialiseren variabelen
     */
    private $parentQuestion;
    private $childQuestionTrue;
    private $childQuestionFalse;
    private $workAround;
    private $solution;

    /**
     * aanmaken van de vriabelen
     */
    public function __construct(Question $parent, $tChild = null, $fChild = null,
        $workAround = null, $solution = null)
    {
        $this->parentQuestion = $parent;
        $this->childQuestionTrue = $tChild;
        $this->childQuestionFalse = $fChild;
        $this->workAround = $workAround;
        $this->solution = $solution;
    }

      /**
     * aanmaken van een nieuw item
     */
    public static function create(Question $parent, $tChild = null, $fChild = null,
        $workAround = null, $solution = null)
    {
        return new QuestionQueue($parent, $tChild, $fChild, $workAround, $solution);
    }

    /*
     * lezen van de gegvens van 1 enkel item
     */
    public static function read($id){
         $questionqueue = SQL::query("SELECT * FROM `question_queue` WHERE `Parent_question_ID` = $id");

        if ($questionqueue->isValid()) {
            return QuestionQueue::create(
                Question::read($questionqueue->fetchField('Parent_question_ID')),
                $questionqueue->fetchField('Child_question_false'),
                $questionqueue->fetchField('Child_question_true'),
                $questionqueue->fetchField('Workaround_ID'),
                $questionqueue->fetchField('Oplossing_ID')
            );
        } else {
            return null;
        }
    }

     /**
     * gegevens naar een array schrijven.
     */
    public function toArray()
    {
        return array(
            "Parent" => $this->parentQuestion,
            "ChildFalse" => $this->childQuestionFalse,
            "ChildTrue" => $this->childQuestionTrue,
            "Workaround" => $this->workAround,
            "Oplossing" => $this->solution
        );
    }

    /**
     * Query voor het updaten van de betreffende tabel
     */
    public function update()
    {
        SQL::execute("INSERT INTO `incident_history` (`History_ID`, `Incident_ID`, `Question_ID`, `Question_Answer`)
                VALUES(NULL,
                      '{$this->Incident_ID}',
                      '{$this->Question_ID}',
                      '{$this->Question_Answer}'");
    }

      /**
     * Query voor deleten van de gegevens uit de gegeven tabel
     */
    public function delete(){

    }


    /**
     * Setters & getters
     */
    public function setChildQuestionFalse($childQuestionFalse)
    {
        $this->childQuestionFalse = $childQuestionFalse;
    }

    public function getChildQuestionFalse()
    {
        return $this->childQuestionFalse;
    }

    public function setChildQuestionTrue($childQuestionTrue)
    {
        $this->childQuestionTrue = $childQuestionTrue;
    }

    public function getChildQuestionTrue()
    {
        return $this->childQuestionTrue;
    }

    public function setParentQuestion($parentQuestion)
    {
        $this->parentQuestion = $parentQuestion;
    }

    public function getParentQuestion()
    {
        return $this->parentQuestion;
    }

    public function setSolution($solution)
    {
        $this->solution = $solution;
    }

    public function getSolution()
    {
        return $this->solution;
    }

    public function setWorkAround($workAround)
    {
        $this->workAround = $workAround;
    }

    public function getWorkAround()
    {
        return $this->workAround;
    }


}
